package com.chan.web.controller.cd;

import java.util.List;

import com.chan.common.annotation.Log;
import com.chan.common.core.controller.BaseController;
import com.chan.common.core.domain.AjaxResult;
import com.chan.common.core.page.TableDataInfo;
import com.chan.common.enums.BusinessType;
import com.chan.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.chan.domain.CdProgramPayNote;
import com.chan.service.ICdProgramPayNoteService;


/**
 * 交付清单Controller
 *
 * @author chan
 * @date 2024-04-30
 */
@Controller
@RequestMapping("/cd/programPayNote")
public class CdProgramPayNoteController extends BaseController
{
    private String prefix = "cd/programPayNote";

    @Autowired
    private ICdProgramPayNoteService cdProgramPayNoteService;

    @RequiresPermissions("cd:programPayNote:view")
    @GetMapping()
    public String programPayNote()
    {
        return prefix + "/programPayNote";
    }

    /**
     * 查询交付清单列表
     */
    @RequiresPermissions("cd:programPayNote:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CdProgramPayNote cdProgramPayNote)
    {
        startPage();
        List<CdProgramPayNote> list = cdProgramPayNoteService.selectCdProgramPayNoteList(cdProgramPayNote);
        return getDataTable(list);
    }

    /**
     * 导出交付清单列表
     */
    @RequiresPermissions("cd:programPayNote:export")
    @Log(title = "交付清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CdProgramPayNote cdProgramPayNote)
    {
        List<CdProgramPayNote> list = cdProgramPayNoteService.selectCdProgramPayNoteList(cdProgramPayNote);
        ExcelUtil<CdProgramPayNote> util = new ExcelUtil<CdProgramPayNote>(CdProgramPayNote.class);
        return util.exportExcel(list, "交付清单数据");
    }

    /**
     * 新增交付清单
     */
    @GetMapping("/add/{relateId}")
    public String add(@PathVariable("relateId") String relateId,ModelMap mmap){
        System.out.println(relateId);
        mmap.put("relateId", relateId);
        return prefix + "/add";
    }

    /**
     * 新增保存交付清单
     */
    @RequiresPermissions("cd:programPayNote:add")
    @Log(title = "交付清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CdProgramPayNote cdProgramPayNote)
    {
        return toAjax(cdProgramPayNoteService.insertCdProgramPayNote(cdProgramPayNote));
    }

    /**
     * 修改交付清单
     */
    @RequiresPermissions("cd:programPayNote:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CdProgramPayNote cdProgramPayNote = cdProgramPayNoteService.selectCdProgramPayNoteById(id);
        mmap.put("cdProgramPayNote", cdProgramPayNote);
        return prefix + "/edit";
    }

    /**
     * 修改保存交付清单
     */
    @RequiresPermissions("cd:programPayNote:edit")
    @Log(title = "交付清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CdProgramPayNote cdProgramPayNote)
    {
        return toAjax(cdProgramPayNoteService.updateCdProgramPayNote(cdProgramPayNote));
    }

    /**
     * 删除交付清单
     */
    @RequiresPermissions("cd:programPayNote:remove")
    @Log(title = "交付清单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cdProgramPayNoteService.deleteCdProgramPayNoteByIds(ids));
    }
}
